﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace Kevin.Framework.Data.Provider
{
    public class SqliteProvider:BuilderProvider
    {
        public override string ParameterPrefix
        {
            get { return "@"; }
        }

        public override string GetDBStringLengthFunction(string data, bool addQuotation)
        {
            throw new NotImplementedException();
        }

        public override string GetDBByteLengthFunction(string data, bool addQuotation)
        {
            throw new NotImplementedException();
        }

        public override string GetDBSubStringStr(string data, int start, int length, bool addQuotation)
        {
            throw new NotImplementedException();
        }

        public override string FormatDateTime(DateTime dt)
        {
            throw new NotImplementedException();
        }

        public override string DBNullToString(string data, string nullStr, bool addQuotation)
        {
            throw new NotImplementedException();
        }

        public override string DBCurrentTimeFunction
        {
            get { throw new NotImplementedException(); }
        }

        public override string DBStrConcatSymbol
        {
            get { throw new NotImplementedException(); }
        }

        public override string DBStatementBegin
        {
            get { throw new NotImplementedException(); }
        }

        public override string DBStatementEnd
        {
            get { throw new NotImplementedException(); }
        }

        public override string DBStatementSeperator
        {
            get { throw new NotImplementedException(); }
        }

        public override IColumnsFormatter ColumnFormatter
        {
            get { throw new NotImplementedException(); }
        }

        public override Database DB
        {
            get { throw new NotImplementedException(); }
        }

        public override System.Data.Common.DbCommand CreateSelectRangCommand(Database db, Query.WhereClip where, int pageIndex, int pageSize, string[] columns)
        {
           
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT ");
            for (int i = 0; i < columns.Length; i++)
            {
                sb.Append(columns[i]);
                if (i < columns.Length - 1)
                    sb.Append(",");
            }
            string strSql = string.Format("{0} FROM {1} limit {2},{3} "
                                            ,sb.ToString()
                                            ,where.ToString()
                                            ,(pageIndex-1)*pageSize
                                            ,pageIndex*pageSize);
            DbCommand cmd = db.CreateCommandByCommandType(System.Data.CommandType.Text, strSql);
            //cmd.CommandText
            base.AddParameters(where, cmd);
            return cmd;
            
        }
    }
}
